package com.baselibrary.permission.factory;

import android.Manifest;

import java.util.ArrayList;

/**
 * @author: 关忆北、
 * @date: 2022/3/14
 * @Des：关于手机权限
 */
public class PermissionFactory extends AbsPermission {

    private final ArrayList<String> mPerList;//未通过的权限

    public PermissionFactory() {
        mPerList = new ArrayList<>();
    }

    public void add(String perName) {
        mPerList.add(perName);
    }

    public ArrayList<String> getPerList() {
        return mPerList;
    }

    @Override
    public String perName(ArrayList<String> srtPer) {
        StringBuilder perBuffer = new StringBuilder();
        for (String s : srtPer) {
            switch (s) {
                case Manifest.permission.CAMERA:
                    if (!perBuffer.toString().contains("相机、"))
                        perBuffer.append("相机、");
                    break;
                case Manifest.permission.READ_EXTERNAL_STORAGE:
                case Manifest.permission.WRITE_EXTERNAL_STORAGE:
                    if (!perBuffer.toString().contains("存储、"))
                        perBuffer.append("存储、");
                    break;
                case Manifest.permission.READ_PHONE_STATE:
                    if (!perBuffer.toString().contains("手机状态、"))
                        perBuffer.append("手机状态、");
                    break;
                case Manifest.permission.READ_CALL_LOG:
                case Manifest.permission.WRITE_CALL_LOG:
                    if (!perBuffer.toString().contains("通话记录、"))
                        perBuffer.append("通话记录、");
                    break;
                case Manifest.permission.CALL_PHONE:
                    if (!perBuffer.toString().contains("拨打电话、"))
                        perBuffer.append("拨打电话、");
                    break;
                case Manifest.permission.READ_CONTACTS:
                case Manifest.permission.WRITE_CONTACTS:
                    if (!perBuffer.toString().contains("通讯录、"))
                        perBuffer.append("通讯录、");
                    break;
                case Manifest.permission.RECORD_AUDIO:
                    if (!perBuffer.toString().contains("麦克风、"))
                        perBuffer.append("麦克风、");
                    break;
                case Manifest.permission.SEND_SMS:
                case Manifest.permission.RECEIVE_SMS:
                case Manifest.permission.READ_SMS:
                    if (!perBuffer.toString().contains("短信、"))
                        perBuffer.append("短信、");
                    break;
                case Manifest.permission.READ_CALENDAR:
                case Manifest.permission.WRITE_CALENDAR:
                    if (!perBuffer.toString().contains("日历、"))
                        perBuffer.append("日历、");
                    break;
                case Manifest.permission.ACCESS_FINE_LOCATION:
                case Manifest.permission.ACCESS_COARSE_LOCATION:
                    if (!perBuffer.toString().contains("位置信息、"))
                        perBuffer.append("位置信息、");
                    break;
                case Manifest.permission.BODY_SENSORS:
                    if (!perBuffer.toString().contains("身体传感器、"))
                        perBuffer.append("身体传感器、");
                    break;

            }
        }
        perBuffer.deleteCharAt(perBuffer.length()-1);
        return perBuffer.toString();
    }
}
